/*(function(doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function() {
            var clientWidth = docEl.clientWidth;
            if (!clientWidth) return;
            docEl.style.fontSize = 20 * (clientWidth / 375) + 'px';
        };
    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);*/
import Vue from 'vue'


//去空格
Vue.prototype.trimStr = function (str){
    return str.replace(/(^\s*)|(\s*$)/g,"")
};


//检查token
Vue.prototype.vCheck = function (){
      let token=''
      let login=''
      let name = "token" + "=";
      let ca = document.cookie.split(';');
      for (let i = 0; i < ca.length; i++) {
          let c = ca[i].split("=");
          if(this.trimStr(c[0])=="token"){
              token=c[1];
          }
      };
      if(token!=''){
        var miwen = '';
        var arr = token.split("/");
        for(var i in arr){
          miwen += String.fromCharCode(arr[i]);
        }
        this.$store.dispatch("tokensync",miwen);
        return true
      }else{
        return false
      };
};

//数组去重
Vue.prototype.unique = function(val){
 
  let arr = val;
  let narr = [];
  let nfrr = {};
  for (let i = 0; i < arr.length; i++) {
    if (!nfrr[arr[i]]) {
      narr.push(arr[i])
      nfrr[arr[i]] = i;
    }
  }
 return narr;
}

//检查用户登录
Vue.prototype.vLogin = function (){
      let login='';
      let name = "login" + "=";
      let ca = document.cookie.split(';');
      for (let i = 0; i < ca.length; i++) {
          let c = ca[i].split("=");
          if(this.trimStr(c[0])=="login"){
              login=c[1];
          }
      };
      if(login!=''){
        //用户已登录
        var miwen = '';
        var arr = login.split("/");
        for(var i in arr){
          miwen += String.fromCharCode(arr[i]);
        }
        this.$store.dispatch("login",miwen);
        return true
      }else{
        //this.$store.dispatch("loginBox");
        return false
      };
};


//检查是否为空
Vue.prototype.Input = (val) => {
  if(val!=''){
    return true
  }else{
    return false
  }
}

//检查密码6-20位
Vue.prototype.Password = (val) => {
  let reg=/^[0-9A-Za-z]{6,20}$/;
  return reg.test(val)
}

//检查是否为数字
Vue.prototype.NumberTest = (val) => {
  let reg=/^[0-9]+.?[0-9]*$/;
  return reg.test(val)
}

//检查是否为邮箱
Vue.prototype.InputEmail = (val) => {
  let reg=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
  return reg.test(val)
}

//检查是否为手机
Vue.prototype.InputTel = (val) => {
  let reg=/^1(3|4|5|7|8)\d{9}$/;
  return reg.test(val)
}